<template>
	<view>

			<u-notify ref="uNotify" message="Hi uView"></u-notify>

		<view class="text-denglu">
			<u--text text="登录吃了么骑手" size="20px" margin="120rpx 0px 0px 100rpx" bold></u--text>
		</view>
		<view class="view-form">
			<u--form labelPosition="left" ref='myForm' :model="userInfo">
				<u-form-item label="账号" prop="userName" borderBottom>
					<u--input v-model="userInfo.userName" border="none" placeholder="请输入您的账号"></u--input>
					<u-icon v-if="userInfo.userName" slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item label="密码" prop="password" borderBottom>
					<u--input v-model="userInfo.password" border="none" placeholder="请输入您的密码" type="password">
					</u--input>
					<u-icon v-if="userInfo.password" slot="right" name="arrow-right"></u-icon>
				</u-form-item>
			</u--form>
		</view>
		<view class="checkbox-qishou">
			<u-checkbox-group>
				<u-checkbox shape="square" label=" " size="14px" @change="checkboxChange"></u-checkbox>
				<u--text text="登录代表你已同意吃了么用户协议,隐私政策,软件使用协议" margin="30rpx 0rpx 0rpx 20rpx" type="info" size="13px">
				</u--text>
			</u-checkbox-group>
		</view>
		<view class="u-page__button-item">
			<u-button text="登录" size="normal" type="primary" @click="nameAndPasswordLogin" :disabled="disabled2"></u-button>
		</view>
		<view>
			<u--text text="手机号登录" size="12px" margin="40rpx 0px 0px 80rpx" bold type="info"
				@click="checkPasswordLogin"></u--text>
		</view>
		<view class="text-uppassword">
			<u--text text="忘记密码" size="12px" margin="0rpx 0px 0px 0rpx" bold type="info" @click="uppassword">
			</u--text>
		</view>
	</view>
</template>

<script>
import { data } from 'uview-ui/libs/mixin/mixin'
	export default {
		data() {
			return {
				userInfo: {
					userName: '', //账号
					password: '' //密码
				},
				disabled2: false, //按钮状态
				rules: {
					phone: [{
							required: true,
							message: '请输入账号',
							trigger: 'blur'
						},
					]
				}
			}
		},
		onLoad() {
				this.disabled2 = true
			},
		methods: {
			checkboxChange(n) {
			          if(n==false){
										this.disabled2 = true
									}else{
										this.disabled2 = false
									}
			      },
			//忘记密码
			uppassword() {
				setTimeout(() => {
					uni.$u.route({
						url: 'pages/getpassword/getpassword'
					})
				}, 1000)
			},
			//页面跳转（邮箱验证登录）
			checkPasswordLogin() {
				setTimeout(() => {
					uni.$u.route({
						url: 'pages/login/login'
					})
				}, 2000)
			},
			//账号密码登录
			nameAndPasswordLogin(){
				this.$myRequest ({
					url:'/login/loginByUser',
					method:'get',
					data:{
						'userName':this.userInfo.userName,
						'password':this.userInfo.password
					}
				}).then(res=>{
					console.log(res)
					uni.setStorageSync('token',res.data.obj.token)
					uni.setStorageSync('id',res.data.obj.user.id)
					uni.setStorageSync('loginName',res.data.obj.user.loginName)
					uni.setStorageSync('userName',res.data.obj.user.userName)
					uni.setStorageSync('phone',res.data.obj.user.phone)
					uni.setStorageSync('avatarId',res.data.obj.avatarId)
					if(res.data.obj.user.role===1){
						uni.navigateTo({
							url: '/pages/zhuceqishou/zhuceqishou',
						})
					}
					if(res.data.obj.user.role===3){
						uni.getLocation({
						    type: 'wgs84',
							geocode:true,
						    success: function (res) {  
						        console.log('当前位置的经度：' + res.longitude);  
						        console.log('当前位置的纬度：' + res.latitude);
								uni.setStorageSync("riderLng",res.longitude);
								uni.setStorageSync("riderLat",res.latitude)
						    }
						})
						uni.navigateTo({
							url: '/pages/workview/orderdisplay/orderdisplay',
						})
					}
					if(res.data.obj.user.role==2){
						this.$refs.uNotify.show({
						            top: 40,
						            type: 'error',
						            color: '#F8F9F9',
						            bgColor: '#F56C6C',
						            message: '您已经是商家了',
						            duration: 1000 * 3,
						            fontSize: 12,
						            safeAreaInsetTop:true
						        })
					}
				}) 
			}
		}
	}
</script>

<style>
	.text-uppassword {
		margin-left: 530rpx;
		margin-top: -30rpx;
	}

	.text-denglu {
		letter-spacing: 3rpx;
		font-family: KaiTi;
	}

	.view-form {
		width: 600rpx;
		margin-top: 30rpx;
		margin-left: 75rpx;
	}

	.u-page__button-item {
		width: 550rpx;
		margin-left: 80rpx;
		margin-top: 100rpx;
	}

	.text-wenben {
		font-size: 12px;
		color: #9B9B9B;
		margin-left: 80rpx;
		margin-top: 10rpx;
	}

	.checkbox-qishou {
		width: 300px;
		margin-left: 80rpx;
		margin-top: 80rpx;
	}
</style>
